<?php
require_once("geoip.inc");
class Zend_Controller_Action_Helper_Location extends Zend_Controller_Action_Helper_Abstract {

	/**
	 * 
	 * @param $ip
	 * @return country obj
	 */
	public function getCountryFromIp($ip) {
		$table = new Country();
		if ($ip == '127.0.0.1') {
			return $table->findById(209);
		}
    	$config = Zend_Registry::get("config");
		$gi = geoip_open($config->geoipdata->file,GEOIP_STANDARD);
		$countryCode = geoip_country_code_by_addr($gi, $ip);
		
		return $table->findByCode($countryCode);
	}
}
?>